package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.CourseTeacherDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.xml.xpath.XPath;
import java.util.List;

/**
 * @author Mr.M
 * @version 1.0
 * @description 课程计划编辑接口
 * @date 2022/9/6 11:29
 */
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService teachplanService;
    @Autowired
    private CourseTeacherService courseTeacherService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true,
            dataType = "Long", paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody @Validated SaveTeachplanDto teachplan) {
        teachplanService.saveTeachplan(teachplan);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划媒资信息解除绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void unbindMedia(@PathVariable("teachPlanId") Long teachPlanId, @PathVariable("mediaId") String mediaId) {
        teachplanService.unbindMedia(teachPlanId,mediaId);
    }

    @ApiOperation("删除课程计划")
    @ApiImplicitParam(value = "id", name = "课程计划Id", required = true,
            dataType = "Long", paramType = "path")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachplan(@PathVariable("id") Long id) {
        teachplanService.deleteTeachplan(id);
    }

    @ApiOperation("移动课程计划排序")
    @ApiImplicitParams({@ApiImplicitParam(value = "id",required = true,dataType = "Long",paramType = "path"),
                        @ApiImplicitParam(value = "move",required = true,dataType = "String",paramType = "path")})
    @PostMapping("/teachplan/{move}/{id}")
    public void moveTeachPlan(@PathVariable("id") Long id,@PathVariable("move") String moveType){
        teachplanService.moveTeachPlan(id,moveType);
    }

    @ApiOperation("查询课程对应的教师列表")
    @GetMapping("/courseTeacher/list/{courseId}")
    public List<CourseTeacherDto> selectTeachTeacher(@PathVariable("courseId") Long courseId){
        Long companyId = 1232141425L;
        return courseTeacherService.list(companyId,courseId);
    }

    @ApiOperation("新增/修改课程教师")
    @PostMapping("/courseTeacher")
    public void updateTeachTeacher(@RequestBody CourseTeacherDto courseTeacherDto){
        courseTeacherService.update(courseTeacherDto);
    }

    @ApiOperation("删除课程教师")
    @DeleteMapping("/courseTeacher/course/{courseId}/{teacherId}")
    public void deleteTeachTeacher(@PathVariable("courseId") Long courseId,@PathVariable("teacherId") Long teacherId){
        courseTeacherService.delete(courseId,teacherId);
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/course/{courseId}")
    public void deleteCourse(@PathVariable("courseId") Long courseId){
        Long companyId = 1232141425L;
        courseTeacherService.deleteCourse(courseId,companyId);
    }
}